<?php

class ControlledVocabTypeTable extends GenericObjectTypeTable {

    public static function getInstance() {
        return Doctrine_Core::getTable('ControlledVocabType');
    }

    public function getOneByIdentifier($identifier) {
        $q = $this->createQuery();
        $q->addWhere('typeValue = ? ', $identifier);
        return $q->fetchOne();
    }

    /**
     * Checks the name is not already in use by a record that doesn't have the
     * same typevalue (Identifier)
     *
     * Returns true if the name is not already in use
     *
     * @param <type> $typeName The name to check
     * @param <type> $typeValue The identifier of the record to ignore in the check
     */
    public function checkIsNameAlreadyInUse($typeName, $typeValue) {
        $q = $this->createQuery();
        $q->addWhere('typeValue <> ?', $typeValue);
        $q->addWhere('typeName = ?', $typeName);
        if ($q->count() > 0) {
            return true;
        } else {
            return false;
        }
    }

}